package com.example.tests;

import java.util.regex.Pattern;
import java.util.concurrent.TimeUnit;
import org.junit.*;
import static org.junit.Assert.*;
import static org.hamcrest.CoreMatchers.*;
import org.openqa.selenium.*;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.ie.InternetExplorerDriver;
import org.openqa.selenium.support.ui.Select;

public class Test1 {
	private WebDriver driver;
	private String baseUrl;
	private StringBuffer verificationErrors = new StringBuffer();
	@Before
	public void setUp() throws Exception {
		driver = new InternetExplorerDriver();
		baseUrl = "http://dev09.dev.dssproj.com/";
		driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
	}

	@Test
	public void test2() throws Exception {
		driver.get(baseUrl + "/uk-en/");
		driver.findElement(By.id("edit-adult")).click();
		driver.findElement(By.id("edit-adult")).clear();
		driver.findElement(By.id("edit-adult")).sendKeys("2");
		driver.findElement(By.id("edit-youth")).clear();
		driver.findElement(By.id("edit-youth")).sendKeys("2");
		driver.findElement(By.id("edit-senior")).clear();
		driver.findElement(By.id("edit-senior")).sendKeys("2");
		driver.findElement(By.id("dialog-element")).click();
		driver.findElement(By.xpath("//form[@id='standard-booking-path-daily-view-form']/div/div[3]/table/tbody/tr[7]/td[6]/div")).click();
		driver.findElement(By.id("cart-continue-top")).click();
		
		driver.findElement(By.id("dialog-element--2")).click();
		driver.findElement(By.id("cart-continue-top")).click();
		driver.findElement(By.cssSelector("#dialog-dialog-element--3 > div.item-list > ul..count-2 > li.first > a.button.ok")).click();
		driver.findElement(By.id("dialog-element--3")).click();
		new Select(driver.findElement(By.id("edit-adult-qdendp-1-1-title"))).selectByVisibleText("Mr");
		driver.findElement(By.id("edit-adult-qdendp-1-1-first-name")).clear();
		driver.findElement(By.id("edit-adult-qdendp-1-1-first-name")).sendKeys("abcd");
		driver.findElement(By.id("edit-adult-qdendp-1-1-last-name")).clear();
		driver.findElement(By.id("edit-adult-qdendp-1-1-last-name")).sendKeys("efgh");
		new Select(driver.findElement(By.id("edit-adult-qdendp-1-1-meal"))).selectByVisibleText("Standard");
		new Select(driver.findElement(By.id("edit-adult-qdendp-2-1-title"))).selectByVisibleText("Miss");
		driver.findElement(By.id("edit-adult-qdendp-2-1-first-name")).clear();
		driver.findElement(By.id("edit-adult-qdendp-2-1-first-name")).sendKeys("joe");
		driver.findElement(By.id("edit-adult-qdendp-2-1-last-name")).clear();
		driver.findElement(By.id("edit-adult-qdendp-2-1-last-name")).sendKeys("bloggs");
		new Select(driver.findElement(By.id("edit-adult-qdendp-2-1-meal"))).selectByVisibleText("Standard");
		new Select(driver.findElement(By.id("edit-youth-qdendp-5-1-title"))).selectByVisibleText("Mr");
		driver.findElement(By.id("edit-youth-qdendp-5-1-first-name")).clear();
		driver.findElement(By.id("edit-youth-qdendp-5-1-first-name")).sendKeys("jimmy");
		driver.findElement(By.id("edit-youth-qdendp-5-1-last-name")).clear();
		driver.findElement(By.id("edit-youth-qdendp-5-1-last-name")).sendKeys("bloggs");
		new Select(driver.findElement(By.id("edit-youth-qdendp-5-1-meal"))).selectByVisibleText("Standard");
		new Select(driver.findElement(By.id("edit-youth-qdendp-6-1-title"))).selectByVisibleText("Miss");
		driver.findElement(By.id("edit-youth-qdendp-6-1-first-name")).clear();
		driver.findElement(By.id("edit-youth-qdendp-6-1-first-name")).sendKeys("efgh");
		driver.findElement(By.id("edit-youth-qdendp-6-1-last-name")).clear();
		driver.findElement(By.id("edit-youth-qdendp-6-1-last-name")).sendKeys("hijk");
		new Select(driver.findElement(By.id("edit-youth-qdendp-6-1-meal"))).selectByVisibleText("Standard");
		new Select(driver.findElement(By.id("edit-senior-qdendp-3-1-title"))).selectByVisibleText("Mr");
		driver.findElement(By.id("edit-senior-qdendp-3-1-first-name")).clear();
		driver.findElement(By.id("edit-senior-qdendp-3-1-first-name")).sendKeys("sree");
		driver.findElement(By.id("edit-senior-qdendp-3-1-last-name")).clear();
		driver.findElement(By.id("edit-senior-qdendp-3-1-last-name")).sendKeys("kanth");
		new Select(driver.findElement(By.id("edit-senior-qdendp-3-1-meal"))).selectByVisibleText("Standard");
		new Select(driver.findElement(By.id("edit-senior-qdendp-4-1-title"))).selectByVisibleText("Mr");
		driver.findElement(By.id("edit-senior-qdendp-4-1-first-name")).clear();
		driver.findElement(By.id("edit-senior-qdendp-4-1-first-name")).sendKeys("hiran");
		driver.findElement(By.id("edit-senior-qdendp-4-1-last-name")).clear();
		driver.findElement(By.id("edit-senior-qdendp-4-1-last-name")).sendKeys("shetty");
		new Select(driver.findElement(By.id("edit-senior-qdendp-4-1-meal"))).selectByVisibleText("Standard");
		driver.findElement(By.id("dialog-element--2")).click();
		driver.findElement(By.id("edit-payment-card-card-number")).clear();
		driver.findElement(By.id("edit-payment-card-card-number")).sendKeys("9582600000000004");
		driver.findElement(By.id("edit-payment-card-card-expiry-date")).clear();
		driver.findElement(By.id("edit-payment-card-card-expiry-date")).sendKeys("01/13");
		driver.findElement(By.id("edit-payment-card-card-holder-name")).clear();
		driver.findElement(By.id("edit-payment-card-card-holder-name")).sendKeys("sree");
		driver.findElement(By.id("edit-payment-card-card-security-code")).clear();
		driver.findElement(By.id("edit-payment-card-card-security-code")).sendKeys("123");
		new Select(driver.findElement(By.id("edit-billing-address-title"))).selectByVisibleText("Mr.");
		driver.findElement(By.id("edit-billing-address-first-name")).clear();
		driver.findElement(By.id("edit-billing-address-first-name")).sendKeys("sree");
		driver.findElement(By.id("edit-billing-address-last-name")).clear();
		driver.findElement(By.id("edit-billing-address-last-name")).sendKeys("kanth");
		driver.findElement(By.id("edit-billing-address-address-line-1")).clear();
		driver.findElement(By.id("edit-billing-address-address-line-1")).sendKeys("sfjslafj");
		driver.findElement(By.id("edit-billing-address-town")).clear();
		driver.findElement(By.id("edit-billing-address-town")).sendKeys("kjfslf");
		driver.findElement(By.id("edit-billing-address-postcode-2")).clear();
		driver.findElement(By.id("edit-billing-address-postcode-2")).sendKeys("jflsfjf");
		driver.findElement(By.id("edit-contact-details-email")).clear();
		driver.findElement(By.id("edit-contact-details-email")).sendKeys("sree@gmail.com");
		driver.findElement(By.id("edit-contact-details-confirm-email")).clear();
		driver.findElement(By.id("edit-contact-details-confirm-email")).sendKeys("sree@gmail.com");
		driver.findElement(By.id("edit-contact-details-phone")).clear();
		driver.findElement(By.id("edit-contact-details-phone")).sendKeys("7999999999");
		driver.findElement(By.id("edit-terms-n-conditions-agree-terms")).click();
		driver.findElement(By.id("dialog-element")).click();
		driver.findElement(By.id("edit-payment-card-card-number")).clear();
		driver.findElement(By.id("edit-payment-card-card-number")).sendKeys("9582600000000004");
		driver.findElement(By.id("edit-payment-card-card-security-code")).clear();
		driver.findElement(By.id("edit-payment-card-card-security-code")).sendKeys("123");
		driver.findElement(By.id("dialog-element")).click();
		// ERROR: Caught exception [ERROR: Unsupported command [selectFrame]]
		driver.findElement(By.name("choice")).click();
		// ERROR: Caught exception [ERROR: Unsupported command [selectWindow]]
		driver.findElement(By.cssSelector("h1..firepath-matching-node")).click();
	}

	@After
	public void tearDown() throws Exception {
		driver.quit();
		String verificationErrorString = verificationErrors.toString();
		if (!"".equals(verificationErrorString)) {
			fail(verificationErrorString);
		}
	}

	private boolean isElementPresent(By by) {
		try {
			driver.findElement(by);
			return true;
		} catch (NoSuchElementException e) {
			return false;
		}
	}
}
